package com.bw.device.net

import androidx.lifecycle.MutableLiveData
import com.bw.common.vm.BaseViewModel
import com.bw.device.entity.DeviceEntity
import com.bw.http.utils.zgr.OkHttpClientManager

class DeviceViewModel:BaseViewModel() {
    val apiService:ApiService = OkHttpClientManager.retrofitInstance.create(ApiService::class.java)


    val deviceSuccess by lazy { MutableLiveData<List<DeviceEntity>>() }
    fun getDevice() {
        executeNetwork(
            { apiService.getDevice() },
            deviceSuccess::postValue
        )
    }
    val addDeviceSuccess by lazy { MutableLiveData<DeviceEntity>() }
    fun addDevice(deviceEntity: DeviceEntity){
        executeNetwork(
            {apiService.addDeceive(deviceEntity)},
            addDeviceSuccess::postValue
        )
    }
    val deleteDeviceSuccess by lazy { MutableLiveData<Boolean>() }
    fun delDevice(id:Int){
        executeNetwork(
            {apiService.DelDeceive(id)},
            deleteDeviceSuccess::postValue
        )
    }
}